home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c1.zip / TYPECONV.C < prev    next >
Text File  |  1987-06-18  |  2KB  |  46 lines

  1.  
  2. /*
  3. ** Demonstration of Type Conversion
  4. ** across assignments.
  5. */
  6. main()
  7.         {
  8.         char c1,c2,c3;
  9.         int i1,i2,i3;
  10.         float f1,f2,f3;
  11.  
  12.         c1 = 'x';       /* no conversion */
  13.         c2 = 1000;      /* int constant demoted to char */
  14.         c3 = 6.02e23;   /* float constant demoted to char */
  15.         printf("%c  %c  %c\n",c1,c2,c3);
  16.  
  17. /* Note that the character value is printed as is; the integer
  18. ** with a value of 1000 is converted to its binary equivalent
  19. ** of 1111101000 and truncated to the first 8 data bits which
  20. ** gives 11101000 or decimal 232 or the Greek symbol "phi"
  21. ** when the ASCII symbol is printed; and the conversion from
  22. ** float to char is meaningless and does not occur.  */
  23.  
  24.         i1 = 'x';       /* char constant promoted to int */
  25.         i2 = 1000;      /* no conversion */
  26.         i3 = 6.02e23;   /* float constant demoted to int */
  27.         printf("%d  %d  %d\n",i1,i2,i3);
  28.  
  29. /* Note that ASCII 'x' has an integer value of 120, and the
  30. ** character constant 'x' is promoted when we assign it to an
  31. ** integer.  The floating point constant is demoted to the
  32. ** largest integer 32767 that is possible in the Microsoft
  33. ** C compiler and that number is returned as an integer. */
  34.  
  35.         f1 = 'x';       /* x char constant promoted to float */
  36.         f2 = 1000;      /* int constant promoted to float */
  37.         f3 = 6.02e23;   /* no conversion */
  38.         printf("%f %f %f\n",f1,f2,f3);
  39.  
  40. /* There are no demoted values, everything is represented as
  41. ** its double precision floating point equivalent!   */
  42.  
  43.         }
  44.  
  45.  
  46.